<?php
/**
 * Created by PhpStorm.
 * User: allen
 * Date: 2019/3/8
 * Time: 12:48
 */

namespace app\index\model;

use think\Model;

class HitsLog extends Model
{
    protected $autoWriteTimestamp = true;

    /**
     * 添加浏览记录
     * @param $uid
     * @param $aid
     * @return bool
     */
    public function addNew($uid,$aid){
        $date = date('Y-m-d',time());
        $map[] = ['uid','eq',$uid];
        $map[] = ['aid','eq',$aid];
        $map[] = ['create_time','between time',["{$date} 00:00:00","{$date} 23:59:59"]];
        $count = $this->where($map)->count();
        if(!$count){
            $data = [
                'uid'=>$uid,
                'aid'=>$aid,
                'create_time'=>time()
            ];
            if(!$this->insert($data)){
                return false;
            }
            return true;
        }else{
            return false;
        }
    }
}